package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.IncomePartJudgeVo;
import com.koocloud.electroplatemanage.pojo.mainpojo.WIP;
import com.koocloud.electroplatemanage.service.MainProductionService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: electroplatemanage
 * @description: 主要生产控制层
 * @author: zww
 * @create: 2020-11-16 18:41
 */
@RestController
@RequestMapping("/mainproduction")
public class MainProductionController {
    static Logger log = Logger.getLogger("mainproduction");
    @Autowired
    MainProductionService mainProductionService;
    /**
     *@Description:
     *@Param: [page, limit, beginTime, endTime, idOrName]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/21
     */
    @RequestMapping(value = "/selectWIPAllData", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectWIPAllData(String page, String limit,String beginTime,String endTime, WIP wip) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }


        //查询所有记录 分页
        return mainProductionService.selectWIPAllData(page,limit,beginTime,endTime,wip);
    }

    @RequestMapping(value = "/selectWIPByWON", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectWIPByWON(String workOrderNumber) {

        return mainProductionService.selectWIPByWON(workOrderNumber);
    }

    @RequestMapping(value = "/selectRouteById", method = RequestMethod.POST, name = "路径查询")
    public ResponseTemplate selectRouteById(@RequestParam("routeId") String routeId){
        return mainProductionService.selectRouteById(routeId);
    }

    /**
     *@Description:在工表修改一条记录
     *@Param: [request, location]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/21
     */
    @RequestMapping(value = "/updateLocation", method = RequestMethod.POST, name = "修改一条记录")
    public ResponseTemplate updateLocation(HttpServletRequest request, String location) {
        String userId = request.getHeader("userId");
        //修改一条记录
        return mainProductionService.updateLocation(userId,location);
    }


    /**
     *@Description: 查询所有生产实绩表数据
     *@Param: [page, limit, beginTime, endTime, idOrName]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/21
     */
    @RequestMapping(value = "/selectOrderResourceAllData", method = RequestMethod.POST, name = "查询所有生产实绩表数据")
    public ResponseTemplate selectOrderResourceAllData(@RequestParam(value = "page") String page, @RequestParam(value = "limit") String limit, @RequestParam(value = "beginTime")String beginTime, @RequestParam(value = "endTime")String endTime, @RequestParam(value = "idOrName")String idOrName) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return mainProductionService.selectOrderResourceAllData(page,limit,beginTime,endTime,idOrName);

    }

    @RequestMapping(value = "/selectOrderResourceListByWON", method = RequestMethod.POST, name = "通过工单号查询生产实绩表列表数据")
    public ResponseTemplate selectOrderResourceListByWON(@RequestParam(value = "workOrderNumber")String workOrderNumber) {

        //通过工单号查询生产实绩表列表数据
        return mainProductionService.selectOrderResourceListByWON(workOrderNumber);

    }
}